<?php
/**

* Controller

*/

class WooController{
private $appHelper;

// 不能实例化，只能通过Controller::run()的方式来执行

private function __construct() {
}

public static function run() {
$instance = new self();

// 加载配置

$instance->init();

// 处理请求

$instance->handleReuqest();

}

private function init() {
	$appHelper = WooControllerApplicationHelper::instance();
	$appHelper->init();
}

private function handleReuqest() {
	$request = new \demo\controller\Request();

	$appController = WooBaseApplicationRegistry::getInstance()->getAppController();

	// 执行完所有Command，有可能存在forward

	while ($cmd = $appController->getCommand($request)) {
	// var_dump($cmd);

	$cmd->execute($request);

	// 把当前Command设为已执行过

	$request->setLastCommand($cmd);

	}

	// 获取视图

	$view = $appController->getView($request);

	// 显示视图

	$this->invokeView($view);

/* $cmdReslover = new \demo\command\CommandReslover();

$cmd = $cmdReslover->getCommand($request);

$cmd->execute($request); */

}

private function invokeView($view) {
	include("demo/view/{$view}.php");

	exit();

}

}